/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年9月3日 下午7:36:26
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.shiro.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.woniu.shiro.domain.User;
import com.woniu.shiro.service.IUserService;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("user")
public class UserController {
	@Autowired
	IUserService us;
	@RequestMapping("/login")
	public String login(User user) {
		//获得一个subject对象
		Subject currentUser = SecurityUtils.getSubject();
		//创建一个UsernamePasswordToken
		if(!currentUser.isAuthenticated()) {
			UsernamePasswordToken token = new UsernamePasswordToken(user.getUname(),user.getUpass());
			token.setRememberMe(true);
			 try {
	            	//登录认证
	                currentUser.login(token);
	               
	                
	            } // ... catch more exceptions here (maybe custom ones specific to your application?
	            catch (AuthenticationException ae) {
	                //unexpected condition?  error?
	            	System.out.println("登录失败");
	            }
			}
		
		return "redirect:/jsp/list.jsp";
	}
}
